const util = require('../../utils/util.js');
const api = require('../../config/api.js');
const user = require('../../utils/user.js');

var num =1;
//获取应用实例
const app = getApp();
import Toast from '../../lib/vant-weapp/toast/toast'
Page({
  data: {
    hotGoods: [],
    message:"1",
    pages:"1",
    show:false,
    delId:"",
    msId:'87'
  },
  // 删除订户
  getUserInfo(event) {
    console.log(event.detail);
    let that = this;
    var data = {
      id:this.data.delId,
      msId:this.data.msId
    }
    util.request(api.deleteUrl,data,"POST").then(function(res) {
      console.log(res)
      if (res.errno === 0) {
        that.setData({
          hotGoods: []
        });
        Toast.success('删除成功');
        that.getlistUrl()
      }
    });
  },
  // 删除弹框取消
  onClose() {
    this.setData({ show: false });
  },
  // 删除按钮
  gotoUrlDelete(event){
    var data = event.currentTarget.dataset
    this.setData({show:true,delId:data.id,msId:data.msid});
  },
  // 跳转搜索页面
  gotoUrlsearch(){
    wx.navigateTo({
      url: '/pages/search/search'
    });
  },
  // 修改商户信息
  gotoUrlModifies(event){
    console.log(event.currentTarget.dataset)
    var data = event.currentTarget.dataset
    wx.navigateTo({
      url: '/pages/addUser/addUser?id='+data.id+'&msid='+data.msid+'&name='+data.username+'&phone='+data.phone+'&address='+data.address+'&email='+data.email
    });
  },
// 上拉加载
  onReachBottom: function () {
    console.log("监听用户上拉拉动作");
    var that = this;
    num++
    this.setData({
     pages:num
    });
    this.getlistUrl()
  },
  onLoad: function(options) {
    console.log("options:" ,options);
    // 页面初始化 options为页面跳转所带来的参数

    this.getlistUrl();
  },
  getlistUrl: function() {
    let that = this;
    var data = {
      companyCode: '',
      mobileNumber: this.data.mobileNumber,
      name: '',
      page: this.data.pages,
      limit: '7'
    }
    util.request(api.listUrl,data).then(function(res) {
      console.log(res)
      if (res.errno === 0) {
        that.setData({
          hotGoods: that.data.hotGoods.concat(res.data.list)
        });
      }
      // wx.hideLoading();
    });
  },
  onReady: function() {
    // 页面渲染完成
  },
  onShow: function() {
    // 页面显示
  },
  onHide: function() {
    // 页面隐藏
  },
  onUnload: function() {
    // 页面关闭
  },
  getCoupon(e) {
    if (!app.globalData.hasLogin) {
      wx.navigateTo({
        url: "/pages/auth/login/login"
      });
    }

    let couponId = e.currentTarget.dataset.index
    util.request(api.CouponReceive, {
      couponId: couponId
    }, 'POST').then(res => {
      if (res.errno === 0) {
        wx.showToast({
          title: "领取成功"
        })
      }
      else{
        util.showErrorToast(res.errmsg);
      }
    })
  },
})